package com.leetcode.August;

import javax.swing.tree.TreeNode;
import java.util.Arrays;

/**
 * @Description: 108. 将有序数组转换为二叉搜索树
 * @Author: Mr.Fxy
 * @CreateTime: 2024-08-31 10:39
 */
public class LC108将有序数组转换为二叉搜索树 {
    public TreeNode sortedArrayToBST(int[] nums) {
        int len=nums.length;
        if(len==0){
            return null;
        }
        TteeNode root=new TreeNode(nums[len/2]);
        root.left = sortedArrayToBST(Arrays.copyOfRange(nums,0,len/2));
        root.right = sortedArrayToBST(Arrays.copyOfRange(nums,len/2+1,len));
        return root;
    }
}
